package com.yjht.online.generate.impl.person.plat.kd;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.XmlUtil;
import com.yjht.online.constants.PathConstant;
import com.yjht.online.generate.GlobalContext;
import com.yjht.online.generate.impl.person.PersonGenerateProssorTemplate;
import com.yjht.online.generate.model.person.PersonModel;
import com.yjht.online.generate.model.person.SysRole;
import com.yjht.online.util.OnLineFileUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.List;


public class PersonGenerateProssorKd extends PersonGenerateProssorTemplate {

    final static Logger logger = LoggerFactory.getLogger(PersonGenerateProssorKd.class);



    @Override
    protected List<PersonModel> hanlerModel(List<PersonModel> personModels) {
        for (PersonModel personModel : personModels) {
            String roleId = deductionRoleId(personModel.getRoleName(),personModel.getOrgCd(),personModel.getCorpCd());
            personModel.setRoleId(roleId);
            personModel.setStatus("1");
        }
        return personModels;
    }

    @Override
    protected String templatePath() {
        return "templates/kd/user.xlsx";
    }

    @Override
    protected String fullOutputPath() {
        String outputPath = PathConstant.KD_PATH + StrUtil.SLASH  + "sysUser.xlsx";
        return outputPath;
    }


    private String deductionRoleId(String roleName, String orgId, String corpCd) {

        List<SysRole> sysRoles = GlobalContext.getSysRoles();
        if (CollectionUtil.isEmpty(sysRoles)) {
            return roleName;
        }
        if (roleName.contains("资金管理岗")) {
            if (orgId.equals(corpCd)) {
                roleName = "总行资金管理岗";
            }
        }
        if (roleName.contains("风险审查岗")) {
            if (orgId.equals(corpCd)) {
                roleName = "总行风险审查岗";
            }
        }
        for (SysRole sysRole : sysRoles) {
            if(sysRole.getRoleName().contains(roleName)){
                return sysRole.getRoleId();
            }

        }
        return roleName;
    }


}
